package com.ruoyi.web.controller.business;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.entity.businessentity.Business;
import com.ruoyi.web.service.BusinessService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/business")
@CrossOrigin
public class BusinessController extends BaseController {

    @Autowired
    private BusinessService businessService;

    /**
     * 查看业务列表
     * @param business
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:business:query')")
    @PostMapping("/query")
    public TableDataInfo query(@RequestBody Business business){
        startPage();
        List<Business> list = businessService.query(business);
        return getDataTable(list);
    }

    /**
     * 查看业务列表
     * @param business
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:business:add')")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Business business){
        int result = businessService.add(business);
        if (result==1)
            return AjaxResult.success();
        else
            return AjaxResult.error();
    }

    /**
     * 修改业务
     * @param business
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:business:edit')")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody Business business){
        int result = businessService.editBusiness(business);
        if (result==1)
            return AjaxResult.success();
        else
            return AjaxResult.error();
    }

    /**
     * 删除业务
     * @param id
     * @return
     */
    @PreAuthorize("@ss.hasPermi('business:business:delete')")
    @GetMapping("/delete/{id}")
    public AjaxResult delete(@PathVariable("id")String id){
        int result = businessService.deleteBusiness(id);
        if (result==1)
            return AjaxResult.success();
        else
            return AjaxResult.error();
    }

}
